<template>
	<div id="elementNewLesson" class="elementNewLesson">
		<group>
			<x-switch title="正课" :value-map="[0, 1]" v-model="status" label-align="left"></x-switch>
			<x-input title="类型名" v-model="value"></x-input>
		</group>

		<div class="error" v-show="error">{{error}}</div>

		<flexbox>
			<flexbox-item>
				<x-button class="flexBtn_confirm" @click.native="confirm">确定</x-button>
			</flexbox-item>
			<flexbox-item>
				<x-button class="flexBtn_cancel" @click.native="cancel">取消</x-button>
			</flexbox-item>
		</flexbox>
	</div>
</template>

<script>
	import bus from '@/event/eventBus'
	import NetWorking from '../../../utils/networking'
	import {Group, XInput, XTextarea, XButton, Flexbox, FlexboxItem, XSwitch} from 'vux'

	const URL = 'list_of_value'
	export default {
		name: "new-list-of-value",
		components: {
			Group,
			XInput,
			XTextarea,
			XButton,
			Flexbox,
			FlexboxItem,
			XSwitch
		},
		data() {
			return {
				value: '',
				sequence: '',
				title: this.$route.params.title,
				params: this.$route.params.params,
				filter: this.$route.params.filter,
				type_list: '',
				error: '',
				status: 1,
			}
		},
		created: function () {
			bus.$emit("barController", 1)
			bus.$emit("setTopSimpleTitle", this.title)

			let _this = this
			NetWorking.doGet(
				'list_of_value/getListOfValueTypeList',
				null,
				{
					params:{
						"type": this.filter
					}
				}
			).then(
				response => {
					let rs = response.data
					if(rs.error_code == 0){
						_this.type_list = rs.list_of_value_type
					}else{
						alert("rs.error_message")
					}
				}
			)
		},
		methods: {
			cancel: function () {
				this.$router.go(-1)
			},
			confirm: function () {

				if(this.value == ''){
					this.error = "请输入所有必填项"
					return
				}

				let element_type = ''

				if(this.status == 1){
					element_type = 'S_LOV_LESSON'
				}else{
					element_type = 'S_LOV_DEMO_LESSON'
				}

				NetWorking.doPost(
					URL,
					null,
					{
						type: element_type,
						value: this.value,
						sequence: this.sequence
					}
				).then(
					response => {
						let rs = response.data
						if(rs.error_code == 0){
							this.$router.go(-1)
						}else{
							alert(rs.error_message)
						}
					}
				)
			}
		}
	}
</script>

<style>
	.elementNewLesson {
		border: solid;
		border-color: #f7f7fa;
		margin-left: 5px;
		margin-right: 5px;
		margin-top: 56px;
		box-shadow: 5px 5px 5px #888888;
		border-radius: 25px;
		background-color: white;
	}

	.buttonRole {
		width: 100%;
		margin-top: 15px;
		border-radius: 25px;
	}
</style>